import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.util.ArrayList;

/**
 * 对方牌库
 */
public class RivalLibrary extends JPanel {
    /**
     * 对手牌的数量
     */
    int DominoCount;
    /**
     * 对方牌库实例
     */
    public static RivalLibrary Instance = new RivalLibrary();
    ArrayList<Dominoes> AllRivalDominoes = new ArrayList<>();
    ArrayList<JLabel> DominoBk = new ArrayList<>();

    /**
     * 对方牌库初始化
     */
    public void Init(){
        FlowLayout f = new FlowLayout(FlowLayout.CENTER);
        Border colorfulLine = BorderFactory.createLineBorder(Color.darkGray);
        DominoCount = 7;
        setBounds(500,25,600,100);
        setBorder(colorfulLine);
        f.setHgap(10);
        f.setVgap(12);
        setLayout(f);
        for(int i = 0;i < DominoCount;i++){
            Dominoes tmp = DominoManager.Instance.GetADomino();
            AllRivalDominoes.add(tmp);
            JLabel jLabel = createRivalDomino();
            DominoBk.add(jLabel);
            add(jLabel);
        }
        String text = String.valueOf(DominoCount);
    }

    /**
     * 对方打出一张牌从对方牌库中删除
     */
    public void RemoveOne(){
        int last = DominoBk.size()- 1;
        remove(DominoBk.get(last));
        DominoBk.remove(last);
        DominoCount --;
        TurnManager.Instance.RivalCountUpdate();
        repaint();
    }

    /**
     *返回一个对方的牌
     * @return jLabel - 对方牌的实例
     */
    public JLabel createRivalDomino(){
        String Path = "./imageSrc/back.png";
        Icon icon = new ImageIcon(Path);
        JLabel jLabel = new JLabel(icon);
        jLabel.setSize(35,75);
        return jLabel;
    }
}
